package com.controller;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.Product_comment;
import com.entity.view.Product_commentView;
import com.service.Product_commentService;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Map;

@RestController
@RequestMapping("/Productcomment")
public class Product_commentController {
    @Autowired
    private Product_commentService productCommentService;







    /**
     * 后端列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params, Product_comment productComment,
                  HttpServletRequest request){
        EntityWrapper<Product_comment> ew = new EntityWrapper<Product_comment>();

        PageUtils page = productCommentService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, productComment), params), params));

        return R.ok().put("data", page);
    }

    /**
     * 前端列表
     */
    @IgnoreAuth
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,Product_comment productComment,
                  HttpServletRequest request){
        EntityWrapper<Product_comment> ew = new EntityWrapper<Product_comment>();

        PageUtils page = productCommentService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, productComment), params), params));
        return R.ok().put("data", page);
    }

    /**
     * 列表
     */
    @RequestMapping("/lists")
    public R list( Product_comment productComment){
        EntityWrapper<Product_comment> ew = new EntityWrapper<Product_comment>();
        ew.allEq(MPUtil.allEQMapPre( productComment, "productComment"));
        return R.ok().put("data", productCommentService.selectListView(ew));
    }

    /**
     * 查询
     */
    @RequestMapping("/query")
    public R query(Product_comment productComment){
        EntityWrapper< Product_comment> ew = new EntityWrapper< Product_comment>();
        ew.allEq(MPUtil.allEQMapPre( productComment, "productComment"));
        Product_commentView productCommentView =  productCommentService.selectView(ew);
        return R.ok("查询汽车种类成功").put("data", productCommentView);
    }

    /**
     * 后端详情
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
        Product_comment productComment = productCommentService.selectById(id);
        return R.ok().put("data", productComment);
    }

    /**
     * 前端详情
     */
    @IgnoreAuth
    @RequestMapping("/detail/{id}")
    public R detail(@PathVariable("id") Integer id){
        Product_comment productComment = productCommentService.selectById(id);
        return R.ok().put("data", productComment);
    }




    /**
     * 后端保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody Product_comment productComment, HttpServletRequest request){
        //ValidatorUtils.validateEntity(productComment);
        productCommentService.insert(productComment);
        return R.ok();
    }

    /**
     * 前端保存
     */
    @RequestMapping("/add")
    public R add(@RequestBody Product_comment productComment, HttpServletRequest request){
        //ValidatorUtils.validateEntity(productComment);
        productCommentService.insert(productComment);
        return R.ok();
    }




    /**
     * 修改
     */
    @RequestMapping("/update")
    @Transactional
    public R update(@RequestBody Product_comment productComment, HttpServletRequest request){
        //ValidatorUtils.validateEntity(productComment);
        productCommentService.updateById(productComment);//全部更新
        return R.ok();
    }





    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
        productCommentService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }

}
